package com.lmk;

import java.security.SecureRandom;
import java.util.Scanner;

/*
* 猜拳游戏
*/
public class Game {
    //获取用户输入内容
    static Scanner sc = new Scanner(System.in);
    //产生随机数字
    static SecureRandom s = new SecureRandom();
    //机器人出拳结果
    static String[] type = {"st", "jd", "bu"};
    static int all = 0;//总次数
    static int win = 0;//赢次数
    static int failed = 0;//输次数
    static int draw = 0;//平局次数

    public static void main(String[] args) {
        System.out.println("===☆======欢迎来到拳皇争霸赛=====☆===");
        String src = "y";
        while ("y".equals(src)) {
            play();
            System.out.println("少侠还想在玩吗？（y/n）");
            src = sc.next();


        }
        System.out.println("===☆======少侠有缘再见=====☆===");
    }

    //开始新的一局
    static void play() {
        //电脑出拳
        String ai =type[s.nextInt(3)];
        //玩家出拳
        System.out.println("请少侠出拳(st.石头, jd.剪刀, bu.布)");
        String player = sc.next();
        //裁决
        int result=jude(player,ai);
        // 4.根据结果提示输赢
         switch (result){

             case -1:

                 System.out.println("胜败乃兵家常事继续努力");
                 failed++;
                 break;
             case 0:

                 System.out.println("英雄所见略同");
                 draw++;
                 break;
             case 1:

                 System.out.println("少侠更胜一筹");
                 win++;
                 break;



         }all++;
         System.out.println("共:"+all+"赢："+win+"平："+draw+"输:"+failed);

    }

    /*
     * 判决输赢
     * @param player
     * @param ai
     * @return -1.玩家输, 0.平局, 1.玩家赢
     * */
    static int jude(String player, String ai) {
        //提示出拳类型
        System.out.println(player + "<===>" + ai);
        int result = 0;
        switch (ai) {
            //如果ai出石头 玩家的三种结果及胜负 否则跳出
            case "st":
                switch (player) {
                    case "st":
                        result = 0;
                        break;
                    case "jd":
                        result = -1;
                        break;
                    case "bu":
                        result = 1;
                        break;
                }break;
            //如果ai出jd 玩家的三种结果及胜负 否则跳出
            case "jd":
                switch (player) {
                    case "st":
                        result = 1;
                        break;
                    case "jd":
                        result = 0;
                        break;
                    case "bu":
                        result = -1;
                        break;

                }break;
            //如果ai出bu 玩家的三种结果及胜负 否则跳出
            case "bu":
                switch (player) {
                    case "st":
                        result = -1;
                        break;
                    case "jd":
                        result = 1;
                        break;
                    case "bu":
                        result = 0;
                        break;
                }break;
        }
        //返回 结果的值 0  1  -1
        return result;
         }


}
